#ifndef slak_tetris_h
#define slak_tetris_h

#include "field.h"
#include "soundm.h"
#include "slak/glui/hiscore_table.h"

namespace slak {

	namespace tetris {

		enum game_state {
			INIT_STATE,
			NORMAL_STATE,
			FAST_FALL_STATE,
			STROBE_FX_STATE,
			GAME_OVER_STATE,
		};

		struct Game {
			static const int tick_delay = 17; // ~60Hz
			static const int score_for_clear[];

			int fall_ticks;
			int ticks_per_normal_fall;
			int ticks_per_fast_fall;
			int ticks_per_strobe_fx;
			int score, level, cleared;

			game_state state;
			Field field;
			Tetrad nextTetrad;

			SoundManager * sm;
			slak::glui::HiScoreTable hi_scores;

			bool can_fast_fall;

			Game();

			void newGame();
			void tick();
			void normalTick();
			void fastFallTick();
			void strobeTick();
			void gameOverTick();
			void dropNextTetrad();
			void enter(game_state st);
			void setLevel(int i);

			void right() { 
				field.moveFalling(1,0); 
				can_fast_fall = true; 
			}
			void left() { 
				field.moveFalling(-1,0); 
				can_fast_fall = true; 
			}
			void rotate() { 
				field.rotateFalling(); 
				can_fast_fall = true; 
			}

			void setSoundManager(SoundManager*sm) { 
				this->sm = sm; 
			}
		};
	} 
} 

#endif
